import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";
import AboutView from "../views/AboutView.vue";
import TopictView from "../views/topic/TopicView";
import TopicContent from "../views/topic/TopicContent";
import ConsumerView from "../views/topic/ConsumerView";
import LogView from "../views/log/LogView.vue";
import RedisView from "../views/redis/RedisIndexView.vue";
import RedisdetailView from "../views/redis/RedisView.vue";
import RediszsetView from "../views/redis/RedisZsetView.vue";
import RedisDataView from "../views/redis/RedisDataView.vue";
import favicon from "@/assets/favicon.png";

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      title: "首页",
    },
  },
  {
    path: "/about",
    name: "about",
    component: AboutView,
    meta: {
      title: "aobut",
      subtitle: "测试",
    },
  },
  {
    path: "/consumer",
    name: "Consumer",
    component: ConsumerView,
    meta: {
      title: "集群",
      subtitle: "",
    },
  },
  {
    path: "/topic/:itemName",
    name: "topic",
    component: TopictView,
    meta: {
      title: "topic",
      subtitle: "",
    },
  },
  {
    path: "/redis/list",
    name: "redisList",
    component: RedisdetailView,
    meta: {
      title: "redis列表",
      subtitle: "",
    },
  },
  {
    path: "/redis/data",
    name: "redisData",
    component: RedisDataView,
    meta: {
      title: "redis数据",
      subtitle: "",
    },
  },
  {
    path: "/redis/zset",
    name: "rediszset",
    component: RediszsetView,
    meta: {
      title: "redis数据集合",
      subtitle: "",
    },
  },
  {
    path: "/log/data",
    name: "log",
    component: LogView,
    meta: {
      title: "Log日志",
      subtitle: "",
    },
  },
  {
    path: "/redis",
    name: "redis",
    component: RedisView,
    meta: {
      title: "Redis",
      subtitle: "",
    },
  },
  {
    path: "/topic/data/:itemName",
    name: "TopicData",
    meta: {
      breadcrumb: "",
      title: "Topic",
    },
    component: TopicContent,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
router.afterEach((to) => {
  document.title = to.meta.title;
  const iconLink =
    document.querySelector("link[rel~='icon']") ||
    document.createElement("link");
  iconLink.type = "image/x-icon";
  iconLink.rel = "icon";
  iconLink.href = to.meta.icon || favicon; // 默认使用UserImage
  document.head.appendChild(iconLink);
});
export default router;
